package edu.mtu.citizenscience.cs.utils;

import android.annotation.SuppressLint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.View;
/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * Holds utilities for dealing with differences in android versions
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public class NewFeatureSupport {
	
	/**
	 * Get the size of the device display
	 * 
	 * @param   display - Display - the display to get the size of
	 * @return	Point - point holding the display size
	 */
	public static Point getDisplaySize(final Display display) 
	{
		// new point to return
	    final Point point = new Point();
	    try 
	    {
	    	// API 13 and later
	        display.getSize(point);
	    }
	    catch (NoSuchMethodError ignore) 
	    { 
	    	// get the display on older devices
	        point.x = display.getWidth();
	        point.y = display.getHeight();
	    }
	    
	    // return the display size
	    return point;
	}
	
	/**
	 * Get the size of the device display
	 * 
	 * @param   view - View - the view to set the background of
	 * @param	graphicPath - String - path to the background graphic
	 * @return	void
	 */
	public static void setBackground(View view, String graphicPath) 
	{
		try 
	    {
			// API 16 and later
			view.setBackground(Drawable.createFromPath(graphicPath));
	    }
	    catch (NoSuchMethodError ignore) 
	    { 
	    	// set background on older devices
			view.setBackgroundDrawable(Drawable.createFromPath(graphicPath));
		}
	}
}
